import { globalIgnores } from 'eslint/config'
import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript'
import pluginVue from 'eslint-plugin-vue'
import skipFormatting from '@vue/eslint-config-prettier/skip-formatting'

// To allow more languages other than `ts` in `.vue` files, uncomment the following lines:
// import { configureVueProject } from '@vue/eslint-config-typescript'
// configureVueProject({ scriptLangs: ['ts', 'tsx'] })
// More info at https://github.com/vuejs/eslint-config-typescript/#advanced-setup

const config: ReturnType<typeof defineConfigWithVueTs> = defineConfigWithVueTs(
  {
    name: 'app/files-to-lint',
    files: ['**/*.{ts,mts,tsx,vue}'],
  },

  globalIgnores(['**/dist/**', '**/dist-ssr/**', '**/coverage/**']),

  pluginVue.configs['flat/essential'],
  vueTsConfigs.recommended,
  skipFormatting,

  {
    plugins: {
      pluginVue: pluginVue,
    },
    rules: {
      'vue/no-mutating-props': 'off', // 不允许组件 prop的改变
      'vue/script-setup-uses-vars': 'error', // 防止<script setup>使用的变量<template>被标记为未使用
    },
  },

  {
    rules: {
      'no-unused-vars': 'error',
      'no-var': 'error',
      'vue/multi-word-component-names': 'off',
      'comma-dangle': [1, 'always-multiline'],
      semi: [1, 'never'],
      'vue/attributes-order': [
        'error',
        {
          order: [
            'DEFINITION',
            'LIST_RENDERING',
            'CONDITIONALS',
            'RENDER_MODIFIERS',
            'GLOBAL',
            ['UNIQUE', 'SLOT'],
            'TWO_WAY_BINDING',
            'OTHER_DIRECTIVES',
            'OTHER_ATTR',
            'EVENTS',
            'CONTENT',
          ],
          alphabetical: false,
        },
      ],
    },
  },

  {
    languageOptions: {
      globals: {
        VNode: true,
        computed: true,
        createApp: true,
        customRef: true,
        defineAsyncComponent: true,
        defineComponent: true,
        defineStore: true,
        effectScope: true,
        getCurrentInstance: true,
        getCurrentScope: true,
        h: true,
        inject: true,
        isProxy: true,
        isReactive: true,
        isReadonly: true,
        isRef: true,
        markRaw: true,
        nextTick: true,
        onActivated: true,
        onAddToFavorites: true,
        onBackPress: true,
        onBeforeMount: true,
        onBeforeUnmount: true,
        onBeforeUpdate: true,
        onDeactivated: true,
        onError: true,
        onErrorCaptured: true,
        onMounted: true,
        onUnmounted: true,
        onUpdated: true,
        provide: true,
        reactive: true,
        readonly: true,
        ref: true,
        resolveComponent: true,
        shallowReactive: true,
        shallowReadonly: true,
        shallowRef: true,
        toRaw: true,
        toRef: true,
        toRefs: true,
        toValue: true,
        triggerRef: true,
        unref: true,
        useAttrs: true,
        useCssModule: true,
        useCssVars: true,
        useSlots: true,
        useRoute: true,
        useRouter: true,
        watch: true,
        watchEffect: true,
        watchPostEffect: true,
        watchSyncEffect: true,
        Component: true,
        ComponentPublicInstance: true,
        ComputedRef: true,
        DirectiveBinding: true,
        EffectScope: true,
        ExtractDefaultPropTypes: true,
        ExtractPropTypes: true,
        ExtractPublicPropTypes: true,
        InjectionKey: true,
        MaybeRef: true,
        MaybeRefOrGetter: true,
        PropType: true,
        Ref: true,
        WritableComputedRef: true,
        onBeforeRouteLeave: true,
        onBeforeRouteUpdate: true,
        onRenderTracked: true,
        onRenderTriggered: true,
        onScopeDispose: true,
        onServerPrefetch: true,
        onWatcherCleanup: true,
        useId: true,
        useLink: true,
        useModel: true,
        useTemplateRef: true,
      },
    },
  },
)

export default config
